﻿using System;
using System.ComponentModel;
#if TASKSUPPORT
using System.Threading;
#endif
using JetBrains.Annotations;

namespace MugenMvvmToolkit.Interfaces.ViewModels
{
    /// <summary>
    ///     Represents the base interface for all view models.
    /// </summary>
    public interface IViewModel : IDisposable, INotifyPropertyChanged, IObservable, ISuspendNotifications
    {
        /// <summary>
        ///     Gets the initialized state of the current view model.
        /// </summary>
        bool IsInitialized { get; }

        /// <summary>
        ///     Gets the busy state of the current view model.
        /// </summary>
        bool IsBusy { get; }

        /// <summary>
        ///     Gets a value that indicates whether this instance is disposed.
        /// </summary>
        bool IsDisposed { get; }

        /// <summary>
        ///     Gets the information message for busy dialog.
        /// </summary>
        object BusyMessage { get; }

#if TASKSUPPORT
        /// <summary>
        /// Gets the cancellation token that uses to cancel an operation when the current view model will be disposed.
        /// </summary>
        CancellationToken DisposeCancellationToken { get; }
#endif
        /// <summary>
        ///     Gets the settings of the current view model.
        /// </summary>
        IViewModelSettings Settings { get; }

        /// <summary>
        ///     Gets the ioc adapter of the  current view model.
        /// </summary>
        IIocAdapter IocAdapter { get; }

        /// <summary>
        ///     Initializes the current view model with specified <see cref="IInitializationContext" />.
        /// </summary>
        /// <param name="context">
        ///     The specified <see cref="IInitializationContext" />.
        /// </param>
        void InitializeViewModel([NotNull]IInitializationContext context);

        /// <summary>
        ///     Begins to indicate that the current view model is busy.
        /// </summary>
        /// <param name="message">
        ///    The specified message for the <see cref="BusyMessage" /> property.
        /// </param>
        /// <returns>Id of the operation.</returns>
        Guid BeginBusy(object message = null);

        /// <summary>
        ///     Ends to indicate that the current view model is busy.
        /// </summary>
        /// <param name="idBusy">Id of the operation to end.</param>
        void EndBusy(Guid idBusy);

        /// <summary>
        ///     Clears all busy operations.
        /// </summary>
        void ClearBusy();

        /// <summary>
        ///Invokes an action after the current view model was initialized, if the view model is initialized action will invoked immediately.
        /// </summary>
        /// <param name="action">The specified delegate to invoke.</param>
        void InvokeAfterInitialization([NotNull]Action<IViewModel> action);

        /// <summary>
        ///     Occurred after disposed current <see cref="IViewModel" />.
        /// </summary>
        event Action<IViewModel> Disposed;
    }
}